package sample.test.et{
	import com.takanafu.haruframework.aopalliance.reflect.Method;
	import mx.collections.ArrayCollection;
	import com.takanafu.haruframework.d2l.invoker.MethodInfo;
	import com.takanafu.haruframework.aop.AfterReturningAdvice;
	import sample.test.ConsoleManager;
	import com.takanafu.haruframework.d2l.util.ApplicationContext;
	import flash.events.Event;
	import com.takanafu.haruframework.aop.reflect.MethodImpl;
	import flash.net.URLRequest;
	import flash.net.URLLoader;

	public class AfterUseHandler implements AfterReturningAdvice{
		private var cm:ConsoleManager;
		private var cnt:Number = 1;
		
		function AfterUseHandler(){
			cm = ApplicationContext.getBean("consoleManager") as ConsoleManager;
		}
		
		public function afterReturning(returnValue:Object,m:Method,args:ArrayCollection,target:Object):MethodInfo{
			cm.println("after Advice");
			var ret:MethodInfo = null;
			var mimpl:MethodImpl = m as MethodImpl;
			
			if(mimpl != null){
				var req:URLRequest = new URLRequest("text.txt");
				var loader:URLLoader = new URLLoader();
				
				loader.addEventListener(Event.COMPLETE,mimpl.invoker.handler);
				loader.load(req);
				ret = new MethodInfo(initializeHandler,MethodInfo.USE_HANDLER);
			}
			
			return ret;
		}
		
		private function initializeHandler(event:Event,method:MethodImpl=null):void{
			cm.println(cnt.toString()+"回目："+event.target.data);
		}
		
	}
}